<!--内部转账验证-->
<template>
  <div class="bg bg1">
    
    <template v-if="account">
        <div class="height60"></div>
        <text class="font60 text2">{{T('二次验证')}}</text>

        <div class="height60"></div>
        <text class="font28 text2 fontz" v-if="account.phoneStr">{{'手机 ' + account.areaCode + ' ' + account.phoneStr}}</text>
        <text class="font28 text2 fontz" v-else>{{'邮箱 ' + account.emailStr}}</text>
        <div class="row">
          <input class="input font30 text2 all" v-model="smsCode" type="number" 
          :placeholder="T('请输入验证码')" maxlength="6" @input="onInput">

          <div class="send" @click="verifiCilci">
            <text class="fongt26 main-t1">{{time==0?T('发送验证码'):time+" S"}}</text>
          </div>
        </div>
        <div class="line line1"></div>

        <div class="ok main-bt1" @click="okClick">
          <text class="font30 text1">{{T('验证')}}</text>
        </div>
    </template>
  </div>
</template>

<script>

import jnavigator from "@/_js/navigator";
import jmodal from "@/_js/modal";
import jhttps from "@/_js/https";

const weexFunction = weex.requireModule("WeexFunction");

import I18N from "@/_i18n/i18n";
var T = I18N.t;

export default {
  
  data() {
    return {
      T:T,      
      time:0, //倒计时
      param:undefined, //提币参数

      account:undefined, //用户信息
      areaCode:"",  //手机区号
      smsCode:"", //验证
    };
  },

  mounted() {
    var param = weex.config;
    this.param =  param.param;
    this.httpUserInfo();
  },

  methods: {
    

	//格式化
	formatNumber(str) {
    if (!str) return '';  
    
    var arr = str.split('@');
    str = arr[0];
		let reg = new RegExp("^(.{"+3+"}).*(.{"+4+"})$");
    str = arr[0].replace(reg, '$1****$2');
    if (arr.length >1) {
      str = str + '@' + arr[1];
    }
		return  str;
	},

  /************************************************* HTTP*/
  //http用户信息
  httpUserInfo() {
    jmodal.showLoad();
    var param = {};
    jhttps.postX("userV2/userDetail",param,true,(data) => {
      jmodal.hideLoad();
      if (data.status == 200) {
        data = data.data;
        try {
          var account = data.account;
          account.phoneStr = this.formatNumber(account.phone);
          account.emailStr = this.formatNumber(account.email);
          account.areaCode = account.phoneUnique.split('-')[0];
          this.account = account;

          
        } catch (error) {
        }
      } else {
        jmodal.toast(data.msg);
      }
    });
  },

   //http提币
    httpsWithdrawal(){
      
      jmodal.showLoad();
      this.isConfirm = false;
      var param = this.param;
      param['smsCode'] = this.smsCode;
      jhttps.postX("uniswap/withdrawal",param,true,(data)=>{
        
        if(data.status == 200){

          setTimeout(() => {
            japi.synchroApi(this.apiId);
          }, 500);

          setTimeout(() => {
            jmodal.hideLoad();
            jmodal.toast('提币成功');
            jnavigator.back();
          }, 5500);
        }else if(data.status == 601) {
          jmodal.hideLoad();
          var param = {'message':T('请先绑定谷歌验证再进行提币。'),
                         'okBtn':T('立即绑定'),
                         'cancelBtn':T('取消')};
          jmodal.confirm(param,(value)=>{
            if(value == "true"){
              jnavigator.open("", "mine/GABind");
            }
          });
        }else{
          jmodal.hideLoad();
          jmodal.toast(data.msg);
        }
      });
    },

    /************************************************* 其他*/
    //倒计时
    timeDown(time,callback){
      var tick = function(){
        setTimeout(() => {
          time--;
          callback(time);
          if(time > 0){
            tick();
          }
        }, 1000);
      };
      tick();
    },
    
    /************************************************* 点击*/
    //获取验证码
    verifiCilci(){
      
      if(this.time > 0){
        return;
      }

      weexFunction.showVerifiSMS(this.account.email, this.account.phone, this.account.areaCode,"TRANSFER_OUT",(e)=>{
        this.time=30;
        this.timeDown(30,(e)=>{
          this.time=e;
        });
      });
    },

    //确定
    okClick(){
      if(this.smsCode.length == 0){
        jmodal.toast(T('请输入验证码'));
        return;
      }
      
      this.httpsWithdrawal();
    },
  },
}
</script>


<style src="@/_css/style.css" ></style>
<style scoped>
.bg {
  flex: 1;
  padding-left: 40px;
  padding-right: 40px;
}
.input{
  height: 80px;
  placeholder-color:#6E7488; 
  margin-top: 10px;
}
.line{
  height:1px;
}
.send {
  justify-content: center;
  align-items: center;
  height:70px;
  border-radius:12px;

  border-width: 1px;

  padding-left: 30px;
  padding-right: 30px;
}
.ok {
  justify-content: center;
  align-items: center;
  height:72px;
  border-radius:12px;
  margin-top: 120px;
}
</style>
